package huoye.shops.huoye.mine.presenter;


import android.os.CountDownTimer;

import huoye.shops.R;
import huoye.shops.base.BasePresenter;
import huoye.shops.base.MineBaseJsonRequestCallback;
import huoye.shops.common.model.SMSCoder;
import huoye.shops.huoye.mine.networt.MineService;
import huoye.shops.huoye.mine.view.IEditAccoundView;
import huoye.shops.huoye.mine.view.IMineView;
import huoye.shops.huoye.user.model.UpdateInfo;
import huoye.shops.huoye.user.model.User;


/**
 * Created by uesr on 2017/7/19.
 */

public class MinePresenter extends BasePresenter<IMineView> {


    private MineService mService;


    //获取商家个人中心
    public void getUser(){
        //   view.showProcessingIndicator();
        mService.getUser(new MineBaseJsonRequestCallback<User>(User.class) {

            @Override
            public void onSuccess(User user) {
                super.onSuccess(user);
                view.getUserData(user);
            }

            //网络请求失败
            @Override
            public void onFailure(String msg, String code, Throwable e) {
                super.onFailure(msg, code, e);
                view.makeToast(msg);
                //   Log.e("testaaa",msg);
            }

            //加载结束
            @Override
            public void onNetworkFail() {
                super.onNetworkFail();
                view.onNetworkFail();
            }

            //加载中
            @Override
            public void onFinish() {
                super.onFinish();
                view.hideProcessingIndicator();
            }
        });
    }



    //检测升级
    public void checkUpdate() {
        mService.checkUpdate(new MineBaseJsonRequestCallback<UpdateInfo>(UpdateInfo.class) {

            //请求成功
            @Override
            public void onSuccess(UpdateInfo updateInfo) {
                super.onSuccess(updateInfo);
                view.onCheckUpdate(updateInfo);
            }

            //网络请求失败
            @Override
            public void onFailure(String msg, String code, Throwable e) {
                super.onFailure(msg, code, e);
                view.makeToast(msg);
            }

            //加载失败
            @Override
            public void onNetworkFail() {
                super.onNetworkFail();
                view.onNetworkFail();
            }

            //加载结束
            @Override
            public void onFinish() {
                super.onFinish();
                view.hideProcessingIndicator();
            }

        });


    }



    @Override
    public void onStart() {
        mService = new MineService();
    }


}
